//
//  MineHalfCard.m
//  BaseProject
//
//  Created by 王盼盼 on 2024/10/30.
//  Copyright © 2024 wangpanpan. All rights reserved.
//

#import "MineHalfCard.h"
#import "MineTopBottomItem.h"
@interface MineHalfCard ()
@property(nonatomic, strong) NSMutableArray<MineItemModel *> *itemModels;
@end

@implementation MineHalfCard
- (void)makeUI {
    [super makeUI];
    self.backgroundColor = UIColor.clearColor;
    
    {
        NSArray *order_pics = @[ImageName.pic_hunliguanjia, ImageName.pic_qingganzixun];
        NSArray *order_titles = @[@"婚礼管家", @"婚前情感咨询"];
        NSArray *order_subTitles = @[@"0元全方位体验", @"随时解答"];
        NSArray<NSNumber *> *order_actions = @[@(ItemActionToolHunLiGuanJia), @(ItemActionToolHunQianQingGanZiXun)];
        NSMutableArray<MineItemModel *> *orderItems = [NSMutableArray array];
        CGFloat orinY = 0;
        for (NSInteger index = 0; index < order_titles.count; index ++) {
            MineItemModel *item = [[MineItemModel alloc]init];
            item.layout = ItemLayoutStack;
            item.action = order_actions[index];
            
            item.picUrl = order_pics[index];
            item.title = order_titles[index];
            item.subTitle = order_subTitles[index];
            item.titleFont = kFontBold(16);
            item.titleColor = rgba(47, 47, 52, 1);
            item.subTitleFont = kFontRegular(12);
            item.subtTitleColor = rgba(137, 137, 145, 1);
            item.itemMargin = 8;
            [orderItems addObject:item];
        }
        CGFloat itemMargin = 10;
        CGFloat itemWidth = ceil((self.width - itemMargin) / order_titles.count);
        for (NSInteger index = 0; index < orderItems.count; index ++) {
            MineTopBottomItem *item = [[MineTopBottomItem alloc]initWithFrame:CGRectMake((itemWidth + itemMargin) * index, orinY, itemWidth, 90 *ADAPTER_WIDTH)];
            [self addSubview:item];
            item.data = orderItems[index];
            // 手势
            item.tag = self.itemModels.count + index;
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickItem:)];
            item.userInteractionEnabled = YES;
            [item addGestureRecognizer:tap];
        }
        [self.itemModels addObjectsFromArray:orderItems];
        self.height = ceil(90 * ADAPTER_WIDTH);
    }
    
    {
        NSArray *order_pics = @[ImageName.banner_zhuanqian];
        NSArray *order_titles = @[@""];
        NSArray *order_subTitles = @[@""];
        NSArray<NSNumber *> *order_actions = @[@(ItemActionNaviQrCode)];
        NSMutableArray<MineItemModel *> *orderItems = [NSMutableArray array];
        CGFloat orinY = self.height + 10;
        for (NSInteger index = 0; index < order_titles.count; index ++) {
            MineItemModel *item = [[MineItemModel alloc]init];
            item.layout = ItemLayoutStack;
            item.action = order_actions[index];
            
            item.picUrl = order_pics[index];
            item.title = order_titles[index];
            item.subTitle = order_subTitles[index];
            item.titleFont = kFontBold(16);
            item.titleColor = rgba(47, 47, 52, 1);
            item.subTitleFont = kFontRegular(12);
            item.subtTitleColor = rgba(137, 137, 145, 1);
            item.itemMargin = 8;
            [orderItems addObject:item];
        }
        CGFloat itemMargin = 0;
        CGFloat itemWidth = self.width;
        for (NSInteger index = 0; index < orderItems.count; index ++) {
            MineTopBottomItem *item = [[MineTopBottomItem alloc]initWithFrame:CGRectMake((itemWidth + itemMargin) * index, orinY, itemWidth, 80 *ADAPTER_WIDTH)];
            [self addSubview:item];
            item.data = orderItems[index];
            // 手势
            item.tag = self.itemModels.count + index;
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickItem:)];
            item.userInteractionEnabled = YES;
            [item addGestureRecognizer:tap];
            
            orinY = item.bottom;
        }
        [self.itemModels addObjectsFromArray:orderItems];
        self.height = orinY;
    }
}
#pragma mark - click
- (void)clickItem:(UITapGestureRecognizer *)ges {
    !self.clickAction ?: self.clickAction(self.itemModels[ges.view.tag]);
}
#pragma mark - lazy
- (NSMutableArray<MineItemModel *> *)itemModels {
    if (!_itemModels) {
        _itemModels = [NSMutableArray array];
    }
    return _itemModels;
}
@end
